package P011_ExplicitDeclarationUID;

import org.junit.Test;

import java.io.Serializable;

/**
 * Desc:&emsp;&ensp; 显示声明UID,可以在版本迭代修改类后，依然能够反序列化
 *
 * @author 李渊&emsp;liyuan7@yusys.com.cn
 * @version 1.0
 * @since V4.3&emsp;2022/2/24
 */
public class ExplicitDeclarationUID {

    private static class Person implements Serializable {
        private static final long serialVersionUID = 1L;
        private String name;

        public String getName() {
            return name;
        }

        public Person setName(String name) {
            this.name = name;
            return this;
        }
        private String age;

        public String getAge() {
            return age;
        }

        public Person setAge(String age) {
            this.age = age;
            return this;
        }
    }

    @Test
    public void TestProducer() {
        Person person = new Person();
        person.setName("张三");
        //序列化
        SerializationUtils.writeObject(person);
    }

    @Test
    public void TestConsumer() {
        //反序列化
        Person p = (Person) SerializationUtils.readObject();
        System.out.println("name=" + p.getName());
    }
}


